/* Lambdas versus Stateful Function Objects */
#include <iostream>
#include <list>
#include <algorithm>

using namespace std;

int lambda3()
{
	list<int> coll = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
	for (auto i : coll)
	{
		cout << i << " ";
	}
	cout << endl;

	list<int>::iterator pos;
	int count = 0;
	pos = remove_if(coll.begin(), coll.end(), [count](int) mutable {
		return ++count == 3;
	});
	coll.erase(pos, coll.end());	// 1 2 4 5 7 8 9 10

	// should use follow
	pos = remove_if(coll.begin(), coll.end(), [&count](int) {
		return ++count == 3;
	});
	coll.erase(pos, coll.end());

	return 0;
}